<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<%@ include file="/WEB-INF/jsp/inc/taglibs.jsp"%>
	<%@ include file="/WEB-INF/jsp/inc/meta.jsp"%>
<script type="text/javascript" src="${approot}/resource/jquery/validate/jquery.validate.js"></script>
   <link href="${approot}/resource/jquery/validate/jquery.validate.css" rel="stylesheet" type="text/css" />
   <link href="${approot}/resource/jquery/validate/style.css" rel="stylesheet" type="text/css" />
   
     <script type="text/javascript">
            /* <![CDATA[ */
            jQuery(function(){
            	leixingchange();
                //jQuery("#huansuan").validate({
                //    expression: "if (VAL) return true; else return false;",
                 //   message: "换算不能为空"
                //});
                jQuery("#jiDate").validate({
                    expression: "if (VAL) return true; else return false;",
                    message: "记账日期不能为空"
                });
                jQuery("#jiPingzheng").validate({
                    expression: "if (VAL) return true; else return false;",
                    message: "记账凭证不能为空"
                });
                jQuery("#remark").validate({
                    expression: "if (VAL) return true; else return false;",
                    message: "备注不能为空"
                });
                jQuery("#yuanjinjia").validate({
                    expression: "if (VAL) return true; else return false;",
                    message: "原进价不能为空"
                });
                //jQuery("#jieCount").validate({
                //    expression: "if (VAL) return true; else return false;",
                //    message: "入库数量不能为空"
               // });
               // jQuery("#jieMoney").validate({
               //     expression: "if (VAL) return true; else return false;",
               //     message: "入库金额不能为空"
              //  });
              //  jQuery("#daiCount").validate({
               //     expression: "if (VAL) return true; else return false;",
               //     message: "出库数量不能为空"
               // });
              //  jQuery("#daiMoney").validate({
               //     expression: "if (VAL) return true; else return false;",
               //     message: "出库金额不能为空"
               // });
                jQuery("#yuCount").validate({
                    expression: "if (VAL) return true; else return false;",
                    message: "余额数量不能为空"
                });
                jQuery("#yuMoney").validate({
                    expression: "if (VAL) return true; else return false;",
                    message: "余额金额不能为空"
                });
               
                 jQuery('#item').validated(function(){
 					//alert("通过验证");
 					do_edit();
 				});
            });
            /* ]]> */
        </script>
        
        <script type="text/javascript">

        function leixingchange()
        {   
        	var val=$("#leixing").val();
        	//alert(val);
        	if(val==1){
            	//$('#choosetable').show();
            	$('#ruku').show();
            	$('#chuku1').hide();
            	$('#chuku2').hide();
            	$("#daiCount").val(0);
            	$("#daiMoney").val(0);
            	$("#daiMan").val(0);
            	$("#daiDept").val(0);
        	}
        	else
        	{
            	$("#jieCount").val(0);
            	$("#jieMoney").val(0);
        		$('#ruku').hide();
            	$('#chuku1').show();
            	$('#chuku2').show();
        	}
        }
        
        function do_edit()
        {   
            var str=$('#item').serializeObject();
            var jsons = $.toJSON(str);
            edit_role(jsons);
        }


        function edit_role(jsons){
 	       $.ajax({
 		   	url:'${approot}/admin/caidetail/edit',
 		   	dataType: 'json',
 		   	contentType: 'application/json',
 			data:jsons,
 			type:'post',
 			beforeSend:function(){
 			  // $('#main').disabled='true';
 			},
 			error:function(request){
 				//alert(S);
 			},
 			success:function(data){
 				 if(data.msg=="error")
 	 			   {
 	 	 			   alert('已经存在,请重新输入');
 	 			   }
 	 			   if(data.msg=="succ")
 	 			   {
 	 				  alert('修改成功');
 	 			   }
 			}
 		   });
 	}
        </script>
        
           <script type="text/javascript">
        
        function show2(id)
        {
            //alert(id);
            $("#s2").load("${approot}/admin/caidetail/cascade/"+id+"/2");
            $("#s3").hide();
            $("#s4").hide();
        }
        function show3(id)
        {
            //alert(id);
             $("#s3").show();
            $("#s3").load("${approot}/admin/caidetail/cascade/"+id+"/3");
            $("#s4").hide();
        }
        function show4(id)
        {
            //alert(id);
            $("#s4").show();
            $("#s4").load("${approot}/admin/caidetail/cascade/"+id+"/4");
        }
        </script>
   
</head>  
  <body style="background:#E8F5FE; padding:15px 18px;" class="scroll_r">
<div id="right_w"><p>当前位置：工程材料管理系统 >>材料明细修改</p></div>

<form method="post" action="" id="item">
  <table border="0" cellpadding="0" cellspacing="1" width="92%" align="center" class="tab_l">
    <tr>
      <td><b>请按要求填写：</b></td>
      <td align="right">带<span style="color:#ff0000;">*</span>为必填</td>
    </tr>
  </table>
  <table border="0" cellpadding="0" cellspacing="1" width="92%" align="center" id="add_tab">
  <tr>
   <th><span style="color:#ff0000; margin:0;">*</span>分类：</th>
   <td>
    <select name="type1" onchange="show2(this.value)">
                            <option value="0">请选择分类</option>
                            <c:forEach items="${types}" var="type">
                            <option value="${type.id}">${type.name}</option>
                            </c:forEach>
                            </select>
                            
                                <div id="s2"></div>
    <div id="s3"></div>
    <div id="s4"></div>
   </td>
   <th>类型：</th>
   <td>
    <select name="leixing" id="leixing" onchange="leixingchange();">
                            <option value="1" <c:if test='${caidetail.leixing==1}'>selected</c:if>>入库</option>
                            <option value="2" <c:if test='${caidetail.leixing==2}'>selected</c:if>>出库</option>
                            </select>
   </td>
  </tr>
  
    <tr>
   <th><span style="color:#ff0000; margin:0;">*</span>记账日期：</th>
   <td><input type="text" id="jiDate" name="jiDate" value="${caidetail.jiDate}" class="Wdate" onFocus="WdatePicker({startDate:'%y-%M-01',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})"/> </td>
   <th>记账凭证：</th>
   <td><input type="text" name="jiPingzheng" value="${caidetail.jiPingzheng}" id="jiPingzheng"></td>
  </tr>
   <tr>
   <th><span style="color:#ff0000; margin:0;">*</span>备注：</th>
   <td><input type="text" name="remark" value="${caidetail.remark}" id="remark"></td>
   <th>原进价：</th>
   <td><input type="text" name="yuanjinjia" value="${caidetail.yuanjinjia}" id="yuanjinjia"></td>
  </tr>
   <tr id="ruku">
   <th><span style="color:#ff0000; margin:0;">*</span>入库数量：</th>
   <td><input type="text" name="jieCount" value="${caidetail.jieCount}" id="jieCount"></td>
   <th>入库金额：</th>
   <td><input type="text" name="jieMoney" value="${caidetail.jieMoney}" id="jieMoney"></td>
  </tr>
   <tr id="chuku1">
   <th><span style="color:#ff0000; margin:0;">*</span>出库数量：</th>
   <td><input type="text" name="daiCount" value="${caidetail.daiCount}" id="daiCount"></td>
   <th>出库金额：</th>
   <td><input type="text" name="daiMoney" value="${caidetail.daiMoney}" id="daiMoney"></td>
  </tr>
   <tr id="chuku2">
   <th><span style="color:#ff0000; margin:0;">*</span>领取人：</th>
   <td><input type="text" name="daiMan" value="${caidetail.daiMan}" id="daiMan"></td>
   <th>领取单位：</th>
   <td><input type="text" name="daiDept" value="${caidetail.daiDept}" id="daiDept"></td>
  </tr>
   <tr>
   <th><span style="color:#ff0000; margin:0;">*</span>余额数量：</th>
   <td><input type="text" name="yuCount" value="${caidetail.yuCount}" id="yuCount"></td>
   <th>余额金额：</th>
   <td><input type="text" name="yuMoney" value="${caidetail.yuMoney}" id="yuMoney"></td>
  </tr>
  
 </table>

  <p id="tab_but">
  <input type="hidden" name="id" value="${caidetail.id}">
   <input type="submit" value="提 交">
   <input type="button" value="返回" onclick="history.go(-1)"></p>
</form>
</body>
</html>
